//author:Budkin Grigory
//project:dchess
package org.amse.grigory.dchess.kernel;

public class Figure {
    //CONSTANTS

    public final static int COLOR_WHITE = 0;
    public final static int COLOR_BLACK = 1;    // Fields
    private int myX,  myY;
    private Moves myMoves,  myEat;
    private String myName;
    // Color white - 0 black - 1
    private int myColor;

    //
    private int myTransformLine;
    private boolean myCanTransform;
    private String myTransformFigure;

    public Figure(int x, int y) {
        myX = x;
        myY = y;
        myMoves = new Moves();
        myEat = new Moves();
    }

    public Figure() {
        myX = 0;
        myY = 0;
        myMoves = new Moves();
        myEat = new Moves();
        myCanTransform = false;
    }

    public Figure(int x, int y, String name) {
        this(x, y);
        myName = name;
    }

    public Figure(String name) {
        this();
        myName = name;
    }
    // Getters

    public final int getX() {
        return myX;
    }

    public final int getY() {
        return myY;
    }

    public final int getMovesCount() {
        return myMoves.getNumber();
    }

    public final int getMoveX(int index) {
        return myMoves.getMoveX(index);
    }

    public final int getMoveY(int index) {
        return myMoves.getMoveY(index);
    }

    public final char getMoveType(int index) {
        return myMoves.getMoveType(index);
    }

    public final int getEatCount() {
        return myEat.getNumber();
    }

    public final int getEatX(int index) {
        return myEat.getMoveX(index);
    }

    public final int getEatY(int index) {
        return myEat.getMoveY(index);
    }

    public final char getEatType(int index) {
        return myEat.getMoveType(index);
    }

    public final int getColor() {
        return myColor;
    }

    public final String getName() {
        return myName;
    }
    // Setters

    public final void setX(int x) {
        myX = x;
    }

    public final void setY(int y) {
        myY = y;
    }

    public final void setMoveX(int index, int x) {
        myMoves.setMoveX(index, x);
    }

    public final void setMoveY(int index, int y) {
        myMoves.setMoveY(index, y);
    }

    public final void setMoveType(int index, char type) {
        myMoves.setMoveType(index, type);
    }

    public final void setEatX(int index, int x) {
        myEat.setMoveX(index, x);
    }

    public final void setEatY(int index, int y) {
        myEat.setMoveY(index, y);
    }

    public final void setEatType(int index, char type) {
        myEat.setMoveType(index, type);
    }

    public final void setColor(int color) {
        myColor = color;
    }

    public final void setName(String name) {
        myName = name;
    }

    public void addTransform(int line, String s) {
        if (s==null){
            return;
        }
        myTransformLine = line;
        myTransformFigure = s;
        myCanTransform = true;
    }

    public int getTransformLine() {
        return myTransformLine;
    }

    public boolean canTransform() {
        return myCanTransform;
    }

    public String getTransformName() {
        return myTransformFigure;
    }

    // Methods
    public final void addMove(int x, int y, char type) {
        myMoves.add(x, y, type);
    }

    public final void deleteMove(int index) {
        myMoves.remove(index);
    }

    public final void addEat(int x, int y, char type) {
        myEat.add(x, y, type);
    }

    public final void deleteEat(int index) {
        myEat.remove(index);
    }

    @Override
    public final Figure clone() {
        Figure temp = new Figure(myX, myY);
        temp.myName = myName;
        temp.myColor = myColor;
        int length = myMoves.getNumber();
        for (int i = 0; i < length; ++i) {
            temp.myMoves.add(myMoves.getMoveX(i), myMoves.getMoveY(i),
                    myMoves.getMoveType(i));
        }
        length = myEat.getNumber();
        for (int i = 0; i < length; ++i) {
            temp.myEat.add(myEat.getMoveX(i), myEat.getMoveY(i),
                    myEat.getMoveType(i));
        }
        temp.myCanTransform = myCanTransform;
        temp.myTransformFigure = myTransformFigure;
        temp.myTransformLine = myTransformLine;
        return temp;
    }
}
